<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>006节流函数</title>
</head>
<body>
    <div class="wrap">
        <input type="text" id="ipt">
    </div>
    <script>
        let oIpt = document.getElementById('ipt')
        function handleInput() {
            console.log('test debounce', this, event)
        }
        function throttle(source, delay) {
            let flag
            let myThrottle = function (...args) {
                let context = this
                if(!flag) {
                    source.apply(context, args)
                    flag = true
                    setTimeout(() => {
                        flag = false
                    }, delay);
                }
            }
            return myThrottle
        }
        let fn = throttle(handleInput, 1000)
        oIpt.addEventListener('input', fn)
    </script>
</body>
</html>